# -*- coding: utf8 -*-
# $Id :  $



# Copyright 2008-2010, Pascal Fautrero & JCharles
#
# This file is part of PyArchiver.
# 
# PyArchiver is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyArchiver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyArchiver.  If not, see <http://www.gnu.org/licenses/>.



# Import packages

import wx                            # This module uses the new wx namespace
import images
import VersionInfos

#_ = wx.GetTranslation            # Define _ or add _ to builtins in your app file

BUFFERED = 1

#---------------------------------------------------------------------------

class My_Canvas(wx.ScrolledWindow):
    def __init__(self, parent, id=-1, size=wx.DefaultSize):
        wx.ScrolledWindow.__init__(self, parent, id,
                                   pos=(0, 0),
                                   size=size,
                                   style=wx.SUNKEN_BORDER)
        
        #-------------------------------------------------------------------
        
        self.parent = parent
        
        #-------------------------------------------------------------------
        
        self.maxWidth  = 1000
        self.maxHeight = 1000
        self.x = self.y = 0
        self.drawing = False
        
        #-------------------------------------------------------------------
        
        self.SetBackgroundColour(wx.WHITE)
        
        #-------------------------------------------------------------------
        
        self.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
        
        #-------------------------------------------------------------------

        bmp = images.Logo_Jacket.GetBitmap()
        self.bmp = bmp
        
        #-------------------------------------------------------------------
        
        self.SetVirtualSize((self.maxWidth, self.maxHeight))
        self.SetScrollRate(30, 30)
        
        #-------------------------------------------------------------------
        
        if BUFFERED:
            # Initialize the buffer bitmap.  No real DC is needed at this point
            self.buffer = wx.EmptyBitmap(self.maxWidth, self.maxHeight)
            dc = wx.BufferedDC(None, self.buffer)
            dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
            dc.Clear()
            self.DoDrawing(dc)
            
        #-------------------------------------------------------------------
            
        # Bind a paint event to an events handler
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        
    #------------------------------------------------------------------------
        
    def getWidth(self):
        return self.maxWidth

     
    def getHeight(self):
        return self.maxHeight

     
    def OnPaint(self, event):
        if BUFFERED:
            # Create a buffered paint DC.  It will create the real
            # wx.PaintDC and then blit the bitmap to it when dc is
            # deleted.  Since we don't need to draw anything else
            # here that's all there is to it
            dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)
        else:
            dc = wx.PaintDC(self)
            self.PrepareDC(dc)
            # Since we're not buffering in this case, we have to
            # paint the whole window, potentially very time consuming
            self.DoDrawing(dc)
     
     
    def DoDrawing(self, dc, printing=False):
        dc.BeginDrawing()
        
        pen = wx.Pen("BLACK", 4, wx.SOLID)
        
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.SetBrush(wx.Brush("#e0f0f0"))     # green lines
        
        for i in range(56, 784, 56):
            dc.DrawRectangle(0,  i, 794, 28)

        if wx.Platform == "__WXGTK__":
            dc.SetTextForeground("BLACK")
            dc.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL))
            dc.DrawText(u"101009_06_0092", 8, 73)
            dc.DrawText(u"101009_06_0093", 8, 101)

        else:
            dc.SetTextForeground("BLACK")
            dc.SetFont(wx.Font(17, wx.SWISS, wx.NORMAL, wx.NORMAL))
            dc.DrawText(u"101009_06_0092", 8, 59)
            dc.DrawText(u"101009_06_0093", 8, 87)

            
        pen.SetCap(wx.CAP_BUTT)
        dc.SetPen(pen)
        dc.DrawLine(397, 56, 397, 756)
        
        pen.SetCap(wx.CAP_BUTT)
        dc.SetPen(pen)
        dc.DrawLine(0, 756, 794, 756)
        
        pen.SetCap(wx.CAP_BUTT)
        dc.SetPen(pen)
        dc.DrawLine(0, 56, 794, 56)


        if wx.Platform == "__WXGTK__":
            dc.SetTextForeground("BLACK")
            dc.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
            dc.DrawText("PyArchiver %s" % VersionInfos.APPLICATIONVERSION_STRING, 70, 32)

        else:
            dc.SetTextForeground("BLACK")
            dc.SetFont(wx.Font(24, wx.SWISS, wx.NORMAL, wx.BOLD))
            dc.DrawText("PyArchiver %s" % VersionInfos.APPLICATIONVERSION_STRING, 70, 8)
        
        dc.DrawBitmap(self.bmp, 0, 0, True)
        
        pen.SetJoin(wx.JOIN_MITER)
        dc.SetPen(pen)
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        dc.DrawRectangle(0, 0, 794, 794)

        
        dc.SetPen(wx.Pen("RED", 1))
        dc.DrawRectangle(0, 0, 1000, 1000)
        
        dc.EndDrawing()


